package com.hmall.trade.listener;

import com.hmall.trade.service.IOrderService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author macro
 * @Date 2025/6/27  12:21
 * @Description 改造余额支付功能
 * 将支付成功后基于OpenFeign的交易服务的更新订单状态接口的同步调用，改为基于RabbitMQ的异步通知。
 */
@Component
public class PayStatusListener {
    @Resource
    private IOrderService orderService;
    @RabbitListener(bindings=@QueueBinding(
            value = @Queue(value = "trade.pay.success.queue",durable = "true"),
            exchange = @Exchange(name="pay.topic",type = ExchangeTypes.DIRECT),
            key = "pay.success"
    ))
    public void listenPaySuccess(Long orderId) {
        orderService.markOrderPaySuccess(orderId);
    }
}